package controller;


import Utils.ConstantUtils;
import Utils.ResponseData;
import entity.SysAccounts;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import service.SysAccountsService;
import vo.SysAccountsVo;


/**
 * 账号(SysAccounts)表控制层
 *
 * @author liujh
 * @since 2020-08-10 17:02:22
 */
@Controller
@Slf4j
@RequestMapping(value = "sysAccounts",produces = "application/json;utf-8")
public class SysAccountsController {
    /**
     * 服务对象
     */
    @Autowired
    private SysAccountsService sysAccountsService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public SysAccounts selectOne(Long id) {
        return this.sysAccountsService.queryById(id);
    }



    @GetMapping("login")
    public String test(){
        log.info("in step=======>");
        return "login";
    }


    /**
     * 登录
     * @param vo
     * @return
     */
    @PostMapping("login")
    @ResponseBody
    public ResponseData login(@RequestBody SysAccountsVo vo){
      /*  UsernamePasswordToken token = new UsernamePasswordToken(vo.getAccount(),vo.getPassword());
        try {
            //vo.setRememberMe(1);
            Subject subject = SecurityUtils.getSubject();
            subject.login(token);
        } catch (AuthenticationException e) {
            token.clear();
            return ResponseData.success(ConstantUtils.CODE_STATUS_FAIL,"用户或密码错误");
        }*/
        return ResponseData.success(ConstantUtils.CODE_STATUS_SUCCESS,ConstantUtils.SUCCESS);
    }
}